using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GlobalAccess {
	public static string GAMEOBJECT_NAME = "Globals";
	
	/* memoize the GameObject that holds all the Components */
	private GameObject g;
	private GlobalIndex index;
	
	private void InitGlobalIndex() {
		if (this.g == null) {
			this.g = GameObject.Find (GlobalAccess.GAMEOBJECT_NAME);
			if (this.g == null) {
				return;
			}
		}
		
		this.index = (GlobalIndex)this.g.GetComponent (GlobalIndex.GLOBAL_INDEX_COMPONENT_NAME);
	}

	public GlobalAccess() {
		this.InitGlobalIndex();
	}
	
	public Component GetGlobalComponent(System.Type t) {
		if (this.index == null) {
			return null;
		}
		
		return this.index.GetGlobalComponent(t);
	}
	
	public Component GetGlobalComponent(string comp_name) {
		if (this.index == null) {
			return null;
		}
		
		return this.index.GetGlobalComponent(comp_name);
	}
}